import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import codegen.builders.CodegenClass;
import codegen.builders.CodegenMethodBase;
import codegen.builders.CodegenType;

@Test
public class CodegenMethodBase_UT {

	CodegenType clazz;
	CodegenMethodBase method;

	@BeforeMethod
	protected void beforeMethod() {
		clazz = new CodegenClass("TestClass");

	}

	public void invocationCode() {
		method = clazz.addMethod("testMethod")
				.addParameter(int.class, "id");
		Assert.assertEquals(method.invocationCode(null, new String[] { "id" }), "testMethod(id)");
		method.addParameter(String.class, "name");
		Assert.assertEquals(method.invocationCode(null, new String[] { "id", "name" }), "testMethod(id, name)");
	}

	public void declarationCode() {
		method = clazz.addMethod("testMethod")
				.addParameter(int.class, "id");
		String testOutput = method.declarationCode(new String[] { "id" });
		System.out.println(testOutput);
		Assert.assertEquals(testOutput, "\tpublic void testMethod (int id) {\n\t}");

		method.addParameter(String.class, "name");
		testOutput = method.declarationCode(new String[] { "id", "name" });
		System.out.println(testOutput);
		Assert.assertEquals(testOutput, "\tpublic void testMethod (int id, String name) {\n\t}");

		method.addBodyLine("int a = 1");
		testOutput = method.declarationCode(new String[] { "id", "name" });
		System.out.println(testOutput);
		Assert.assertEquals(testOutput, "\tpublic void testMethod (int id, String name) {\n\t\tint a = 1;\n\t}");

		method.addBodyLine("int b = 2");
		testOutput = method.declarationCode(new String[] { "id", "name" });
		System.out.println(testOutput);
		Assert.assertEquals(testOutput, "\tpublic void testMethod (int id, String name) {\n\t\tint a = 1;\n\t\tint b = 2;\n\t}");
	}

	public void interfaceCode() {
		method = clazz.addMethod("testMethod")
				.addParameter(int.class, "id");
		String testOutput = method.interfaceCode(new String[] { "id" });
		System.out.println(testOutput);
		Assert.assertEquals(testOutput, "\tpublic void testMethod (int id);");
		method.addParameter(String.class, "name");
		System.out.println(testOutput);
		Assert.assertEquals(method.interfaceCode(new String[] { "id", "name" }), "\tpublic void testMethod (int id, String name);");

	}

}
